bind-x
Creates a new function with a bound sequence of arguments.
module.exports
⇒ function
⏏
The bind() method creates a new function that, when called, has its this
keyword set to the provided value, with a given sequence of arguments
preceding any provided when the new function is called.
Kind: Exported member
Returns: function
- The bound function.
Throws:
TypeError
If target is not a function.
Param | Type | Description |
---|
target | function | The target function. |
thisArg | * | The value to be passed as the this parameter to the target function when the bound function is called. The value is ignored if the bound function is constructed using the new operator. |
[args] | ...* | Arguments to prepend to arguments provided to the bound function when invoking the target function. |
Example
import bind from 'bind-x';
this.x = 9;
const module = {
x: 81,
getX: function() {
return this.x;
},
};
console.log(module.getX());
const retrieveX = module.getX;
console.log(retrieveX());
const boundGetX = bind(retrieveX, module);
console.log(boundGetX());